﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.Mtool.FSM;
using MToolStudio.Render;
using MToolStudio.UI;

namespace MToolStudio
{
    public class TourListItem : ListViewItem
    {
        private Tour tour;
        private TourR uiTour;

        public TourListItem(Tour t, Dictionary<string, IRenderable> uiMapping)
            :base(t.ToString())
        {
            tour = t;
            uiTour = new TourR(t);            
            foreach (Action a in t.Actions)
            {
                if (!uiMapping.ContainsKey(a.Id))
                {
                    Logger.Instance.Error("Error in generating tour view: cannot find ActionR with id {0}", a.Id);
                }
                else
                {
                    if(uiMapping[a.Id] is ActionR)
                        uiTour.ActionRs.Add(uiMapping[a.Id] as ActionR);
                    else
                        Logger.Instance.Error("Error in generating tour view: type not ActionR with id {0}", a.Id);
                }
            }
            if (t.Entry == null || !uiMapping.ContainsKey(t.Entry.Id) || !(uiMapping[t.Entry.Id] is StateR))
            {
                Logger.Instance.Error("Error in generating tour view: cannot find entry stateR");
            }
            else
            {
                UITour.EntryR = uiMapping[t.Entry.Id] as StateR;
            }
            Checked = true;
        }

        public TourR UITour
        {
            get { return uiTour; }
        }
    }
}
